<!-- 
All rights Reserved, Designed By www.youyacao.com 
@Description:卡密列表
@author:成都市一颗优雅草科技有限公司     
@version 松鼠聚合直播系统v2.0
注意：本前端源码遵循 MulanPSL-2.0开源协议（木兰宽松许可证）本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584

 -->


<template>
    <div>
        <van-nav-bar
                title="所有卡密"
                left-text="返回"
                left-arrow
                fixed
                @click-left="onClickLeft"
        />
        <div style="padding-top: 46px;">
            <van-dropdown-menu>
                <van-dropdown-item v-model="value1" :options="option1" @change="changeTab" />
                <van-dropdown-item v-model="value2" :options="option2" @change="changeTab" />
            </van-dropdown-menu>
            <div>
                <div class="item-box" v-for="(item,index) in list.data">
                    <van-row class="item-title">
                        <van-col span="24" class="order">{{item.title}}</van-col>
                    </van-row>
                    <div class="item-row">激活码：</div>
                    <div class="item-row text" :style="item.actived ? 'color:red;' : ''">{{item.card_no}}</div>
                    <div class="item-row">可用天数：{{item.use_days}}</div>
                    <div class="item-row">创建时间：{{item.create_time}}</div>
                    <div class="item-row" v-if="item.actived" style="border-bottom: #dcdee1 1px solid;">使用时间：{{item.active_time}}</div>
                    <div class="item-row" v-if="item.actived">使用会员：{{item.active_user}}</div>
                </div>
                <van-pagination
                        v-model="list.current_page"
                        :total-items="list.total"
                        :items-per-page="list.per_page"
                        @change="changePage"
                        v-if="list.last_page>1"
                />
            </div>
        </div>
    </div>
</template>

<script>
    import global_ from '../Global';
    import { Toast } from 'vant';
    export default {
        name: "cardlist",
        data(){
          return {
              value1: 0,
              value2: '0',
              option1: [
                  { text: '未使用', value: 0 },
                  { text: '已使用', value: 1 },
              ],
              option2: [
                  { text: '所有类型', value: '0' },
                  { text: '1日体验卡', value: '1' },
                  { text: '7日周卡', value: '7' },
                  { text: '31日月卡', value: '31' },
                  { text: '90日季卡', value: '90' },
                  { text: '365日年卡', value: '365' },
                  { text: '终身免费卡', value: '1000' },
              ],
              list:[]
          }  
        },
        created(){
          this.loadInfo(1);
        },
        methods:{
            onClickLeft:function () {
                this.$router.go(-1);
            },
            changeTab:function () {
                this.loadInfo(1);
            },
            changePage:function(page){
                this.loadInfo(page);
            },
            loadInfo:function (page) {
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '加载中...'
                });
                this.$axios.get(global_.serverUrl+"admin/card/own_cards",{
                    params:{
                        active:this.value1,
                        cardtype:this.value2,
                        page:page
                    }
                }).then((res)=>{
                    toast.clear();
                    if(res.code == 1){
                        this.list = res.data;
                    }
                }).catch(()=>{
                    toast.clear();
                });
            }
        }
    }
</script>

<style scoped>
    .item-box{
        background: #ffffff;
        padding:5px 10px;
        margin: 10px 0px;
    }
    .item-box .item-title{
        border-bottom: #dcdee1 1px solid;
        padding: 10px;
        font-size: 14px;
    }
    .item-box .item-title .order{
        font-weight: bold;
    }
    .item-box .item-title .money{
        text-align: right;
        font-size: 16px;
    }
    .item-row{
        color: #7d7e80;
        padding: 5px 10px;
        font-size: 12px;
    }
    .item-box .text{
        background: #f8f8f8;
        border-radius: 10px;
        padding: 20px;
    }
</style>
